<?
include_once ($_SERVER['DOCUMENT_ROOT']."/inc/conn.inc.php");
include_once ($_SERVER['DOCUMENT_ROOT']."/inc/function.inc.php"); ##property 파일 인크루드됨.
include_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.inc.php");

    $invoiceCd = $_GET[inv];
    if(!$invoiceCd) $invoiceCd = 6;
    $curDate = date("Y-m-d H:i:s");
    $query = "SELECT companyKR, compNo, owner, companyEN, addrKR, addrEN, phone, fax, email, bank, compType, compPart, homepage FROM tblConfig";
    $selfSql = mssql_query($query);
    $selfInfo = mssql_fetch_array($selfSql);

    $query = "SELECT A.invoiceCd, B.companyKR, REPLACE(CONVERT(varchar, CAST(A.amount AS money), 1), '.00', '') amt, CASE WHEN A.updateDt IS NOT NULL THEN CONVERT(varchar(19), A.updateDt, 121) ELSE CONVERT(varchar(19), A.addDt, 121) END wDate ";
    $query .= "FROM tblInvoice A LEFT JOIN tblCompany B ON A.compCd=B.compCd WHERE A.invoiceCd={$invoiceCd}";
    $invoiceSql = mssql_query($query);
    $invoiceInfo = mssql_fetch_array($invoiceSql);

    $query = "SELECT B.billCd, B.expressCd, B.issueDt, B.consignee, B.remarks, B.destAddr, B.weightTon, B.cargoTon, REPLACE(CONVERT(varchar, CAST(B.totalRate AS money), 1), '.00', '') totalRate, ";
    $query .= "REPLACE(CONVERT(varchar, CAST(B.compDCAmount AS money), 1), '.00', '') compDCAmount,  REPLACE(CONVERT(varchar, CAST(B.compOilAmount AS money), 1), '.00', '') compOilAmount, ";
    $query .= "REPLACE(CONVERT(varchar, CAST(B.compExtraCharge AS money), 1), '.00', '') compExtraCharge,  REPLACE(CONVERT(varchar, CAST(B.compTotalInvAmount AS money), 1), '.00', '') compTotalInvAmount, A.flag ";
    $query .= "FROM tblIncome A LEFT JOIN tblExpress B ON A.billCd=B.billCd ";
    $query .= "WHERE A.invoiceCd={$invoiceCd}";
    $detailSql = mssql_query($query);
    //$detailInfo = mssql_fetch_array($detailSql);
?>
<script language = "JavaScript" src="/inc/js/ScriptX_TAG_SCM.js"></script>
<script>initScriptX("contexts", "100%", "100%"); </script>

<script for=window event=onload>
    printWindow(document.contexts, "<?=$curDate?>");
    //self.close();
</script>


<script language="JavaScript">
    function printWindow(objName, DAY2) {
        var footer = "출력일시 : " + DAY2;
        objName.printing.header = "";
        objName.printing.footer = ""; //footer;
        objName.printing.portrait = false; // false 는 가로인쇄
        objName.printing.leftMargin = 15.0;
        objName.printing.topMargin = 5.0;
        objName.printing.rightMargin = 15.0;
        objName.printing.bottomMargin = 3.0;
        objName.printing.Print(false);
    }
</script>
<style>
    #detail {
        clear:both;
        margin-top:50px;
        height: 550px;
        border-bottom: 3px #186096 solid;
    }
    #header div {
        float:left;
        height:23px;
        font-size:9pt;
        border:1px #333 solid;
        margin-left:-1px;
        margin-bottom:1px;
        font-weight:bolder;
        text-align: center;
    }

    #content, #tail {
        clear:both;
    }
    #content div {
        float:left;
        height:20px;
        font-size:11px;
        border-bottom:1px #333 solid;
        margin-top:-1px;
        text-align: center;
    }
    #tail div {
        float:left;
        height:24px;
        font-size:9pt;
        border:1px #333 solid;
        margin-left:-1px;
        text-align: center;
    }
</style>
<body>
<div style="text-align:center;border-bottom:3px #186096 solid;height:155px;">
    <div style="width:100%;height:100px;vertical-align:middle;font-size:17pt;font-weight:bolder;"><img src="/img/logo.jpg"><?=$selfInfo['companyEN']?></div>
    <div style="width:100%;height:17px;vertical-align:middle;font-size:10px;"><?=$selfInfo['addrEN']?></div>
    <div style="width:100%;height:17px;vertical-align:middle;font-size:10px;">Tel: <?=$selfInfo['phone']?> / Fax: <?=$selfInfo['fax']?></div>
    <div style="width:100%;height:17px;vertical-align:middle;font-size:10px;">Homepage: <?=$selfInfo['homepage']?> / E-mail: <?=$selfInfo['email']?></div>
</div>
<div style="clear:both;text-align:center;margin-top:15px;">
    <div style="width:200px;height:35px;vertical-align:middle;font-size:17pt;font-weight:bolder;border:3px #186096 outset;margin:auto;">거 래 명 세 표</div>
</div>
<div style="margin-top:25px;">
    <div style="float:left;width:300px;height:20px;font-size:9pt;border-bottom:1px #666 solid;padding-left:10px;">DATE : <?=substr($invoiceInfo['wDate'],0,10)?></div>
    <!--<div style="float:right;width:200px;height:20px;font-size:9pt;border-bottom:1px #666 solid;padding-left:10px;">INVOICE No. <?=substr($invoiceInfo['wDate'],0,4)?>-<?=$invoiceInfo['invoiceCd']?></div>-->
</div>
<div style="clear:both;margin-top:20px;">
    <div style="float:left;width:300px;height:20px;font-size:9pt;border-bottom:1px #666 solid;padding-left:10px;">T &nbsp; O : <?=iconvDecode($invoiceInfo['companyKR'])?></div>
    <div style="float:right;width:200px;height:20px;font-size:9pt;border-bottom:1px #666 solid;padding-left:10px;">AMOUNT : <b style="font-size:10pt;">\ <?=$invoiceInfo['amt']?></b></div>
</div>
<div id="detail">
    <div id="header">
        <div style="margin-left:1px;width:110px;"><p>BILL NO</p></div>
        <div style="width:100px;"><p>DESTINATION</p></div>
        <div style="width:90px;"><p>CONSIGNEE</p></div>
        <div style="width:149px;"><p>MEMO</p></div>
        <div style="width:50px;"><p>C/T</p></div>
        <div style="width:50px;"><p>WEIGHT</p></div>
        <div style="width:80px;"><p>공급가</p></div>
        <div style="width:80px;"><p>D/C</p></div>
        <div style="width:80px;"><p>유류할증료</p></div>
        <div style="width:80px;"><p>기타비용</p></div>
        <div style="width:80px;"><p>청구금액</p></div>
    </div>
<?
    while($detailInfo = mssql_fetch_array($detailSql))
	{
	    $ttlTotalRate += str_replace(",","",$detailInfo['totalRate']);
	    $ttlCompDCAmount += str_replace(",","",$detailInfo['compDCAmount']);
	    $ttlCompOilAmount += str_replace(",","",$detailInfo['compOilAmount']);
	    $ttlCompExtraCharge += str_replace(",","",$detailInfo['compExtraCharge']);
	    $ttlCompTotalInvAmount += str_replace(",","",$detailInfo['compTotalInvAmount']);
?>
    <div id="content">
        <div style="margin-left:1px;width:110px;border-left:1px #333 solid;"><p><?=$detailInfo['billCd']?></p></div>
        <div style="width:101px;"><p><?=$detailInfo['destAddr']?></p></div>
        <div style="width:90px;"><p><?=$detailInfo['consignee']?></p></div>
        <div style="width:150px;"><p><?=iconvDecode($detailInfo['remarks'])?></p></div>
        <div style="width:50px;text-align:center;"><p><?=$detailInfo['cargoTon']?></p></div>
        <div style="width:50px;text-align:right;padding-right:3px;"><p><?=$detailInfo['weightTon']?></p></div>
        <div style="width:78px;text-align:right;padding-right:3px;"><p><?=$detailInfo['totalRate']?></p></div>
        <div style="width:78px;text-align:right;padding-right:3px;"><p><?=$detailInfo['compDCAmount']?></p></div>
        <div style="width:78px;text-align:right;padding-right:3px;"><p><?=$detailInfo['compOilAmount']?></p></div>
        <div style="width:78px;text-align:right;padding-right:3px;"><p><?=$detailInfo['compExtraCharge']?></p></div>
        <div style="width:78px;text-align:right;padding-right:3px;border-right:1px #333 solid;"><p><?=$detailInfo['compTotalInvAmount']?></p></div>
    </div>
<?
    }
?>
    <div id="tail">
        <div style="margin-left:1px;margin-top:-1px;width:554px;font-weight:bolder;height:25px;"><p>소 계</p></div>
        <div style="width:77px;margin-top:-1px;height:25px;text-align:right;padding-right:3px;font-weight:bolder;"><p>\ <?=number_format($ttlTotalRate,0)?></p></div>
        <div style="width:77px;margin-top:-1px;height:25px;text-align:right;padding-right:3px;font-weight:bolder;"><p>\ <?=number_format($ttlCompDCAmount,0)?></p></div>
        <div style="width:77px;margin-top:-1px;height:25px;text-align:right;padding-right:3px;font-weight:bolder;"><p>\ <?=number_format($ttlCompOilAmount,0)?></p></div>
        <div style="width:77px;margin-top:-1px;height:25px;text-align:right;padding-right:3px;font-weight:bolder;"><p>\ <?=number_format($ttlCompExtraCharge,0)?></p></div>
        <div style="width:77px;margin-top:-1px;height:25px;text-align:right;padding-right:3px;font-weight:bolder;"><p>\ <?=number_format($ttlCompTotalInvAmount,0)?></p></div>

        <div style="clear:both;margin-left:1px;width:554px;font-weight:bolder;height:25px;margin-top:2px"><p>청구금액</p></div>
        <div style="width:401px;height:25px;text-align:right;padding-right:3px;font-weight:bolder;margin-top:2px"><p>\ <?=$invoiceInfo['amt']?></p></div>
    </div>
</div>
<div id="bottom" style="margin-top:20px;">
    <div style="float:left;width:250px;height:100px;text-align:center;border:1px #333 solid;vertical-align:middle;">
        <p style="margin-top:10px;">
            <?=str_replace("\\n","<br>",iconvDecode($selfInfo['bank']))?>
            <br>
            <br>※ 송금후 연락 바랍니다.
        </p>
    </div>
    <div style="float:right;width:320px;height:100px;font-size:12pt;text-align:center;font-weight:bolder;border:1px #FFF solid;vertical-align:middle;">
        <p style="margin-top:10px;">
            <span style="font-size:10pt;font-weight:normal"><?=iconvDecode($selfInfo['addrKR'])?></span>
            <br> <?=iconvDecode($selfInfo['companyKR'])?>
            <br>
            <br> 대 표 : <?=iconvDecode($selfInfo['owner'])?>
        </p>
    </div>
</div>

</body>
</html>